/*==============================================================================
案例4：足球运动员价值预测（随机森林+SHAP可解释性分析）
作者：张立强
日期：2025-11-03
目的：使用H2O机器学习预测球员市场价值，并通过SHAP值解释模型
==============================================================================*/

clear all
set more off

// 设置工作目录
cd "/Users/mac/git/stata"

// 创建输出目录
capture mkdir output
capture mkdir output/cases
capture mkdir output/cases/figures

// 创建日志文件
log using "output/case04_fifa_player_value.log", replace

/*------------------------------------------------------------------------------
第1步：数据加载与探索
------------------------------------------------------------------------------*/

display as text _n "=" * 80
display as text "案例4：足球运动员价值预测（H2O + SHAP）"
display as text "=" * 80

// 加载FIFA球员数据
display as text _n ">>> 步骤1：加载FIFA球员数据"
use "https://www.stata.com/users/lil/fifa", clear

// 数据概览
describe
summarize

// 检查数据结构
display as text _n ">>> 数据维度："
display as result "观测数: " _N
display as result "变量数: " c(k)

/*------------------------------------------------------------------------------
第2步：数据可视化 - 市场价值分布
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤2：可视化市场价值分布"

// 生成百万欧元单位的市场价值
generate mil_average_market_value = average_market_value / 1000000

// 按位置绘制箱线图
graph hbox mil_average_market_value, over(position) ///
    title("Market Value Distribution by Position") ///
    ytitle("Market Value (in millions €)") ///
    note("Data source: FIFA 2023") ///
    scheme(s2color)
graph export "output/cases/figures/case04_01_value_by_position.png", replace

// 描述性统计
display as text _n ">>> 市场价值统计（百万欧元）："
tabstat mil_average_market_value, by(position) statistics(n mean sd min max) format(%9.2f)

// 识别最高价值球员
display as text _n ">>> Top 10 最高价值球员："
gsort -mil_average_market_value
list name position age nationality mil_average_market_value in 1/10, clean

/*------------------------------------------------------------------------------
第3步：对数变换处理右偏分布
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤3：对数变换处理右偏分布"

// 生成对数市场价值
generate ln_average_market_value = log(average_market_value)

// 比较变换前后的变异系数
quietly summarize average_market_value
scalar cv_original = r(sd) / r(mean)
display as result "原始市场价值的变异系数(CV): " %6.2f cv_original

quietly summarize ln_average_market_value
scalar cv_log = r(sd) / r(mean)
display as result "对数市场价值的变异系数(CV): " %6.2f cv_log

display as text "对数变换将CV从 " %4.0f (cv_original*100) "% 降至 " %4.0f (cv_log*100) "%"

// 可视化对数变换效果
histogram ln_average_market_value, ///
    title("Distribution of Log Market Value") ///
    xtitle("Log(Market Value)") ///
    ytitle("Density") ///
    normal ///
    scheme(s2color)
graph export "output/cases/figures/case04_02_log_value_distribution.png", replace

/*------------------------------------------------------------------------------
第4步：H2O初始化与数据准备
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤4：H2O初始化"

// 启动H2O集群
h2o init

// 将当前数据传输到H2O框架
_h2oframe put, into(fifa) current

// 查看H2O数据框信息
_h2oframe describe fifa

// 转换分类变量为枚举类型（H2O要求）
display as text _n ">>> 转换分类变量为枚举类型"
_h2oframe toenum position nationality league_rank, replace

/*------------------------------------------------------------------------------
第5步：训练集/测试集分割
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤5：数据分割（80% 训练，20% 测试）"

// 80/20分割，设置随机种子保证可重复性
_h2oframe split fifa, into(train test) split(0.8, 0.2) rseed(19)

// 查看分割结果
_h2oframe describe train
_h2oframe describe test

/*------------------------------------------------------------------------------
第6步：定义预测变量
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤6：定义预测变量"

// 定义全局宏：预测变量列表
global predictors "position age height nationality league_rank ///
    total_played_games average_minutes_played ///
    average_assists_per_game total_assists assist_per_minute ///
    average_goals_per_game total_goals goals_per_minute ///
    total_yellow_cards team_win_ratio data_year"

display as text "预测变量: $predictors"

/*------------------------------------------------------------------------------
第7步：随机森林回归建模
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤7：随机森林回归（超参数调优）"

// 训练随机森林，使用3折交叉验证，调优树的数量（20-80）
h2oml rfregress ln_average_market_value $predictors, ///
    frame(train) ///
    cv(3) ///
    h2orseed(19) ///
    ntrees(20(10)80) ///
    into(rf)

// 查看模型摘要
h2oml describe rf

// 获取最佳模型的交叉验证性能
display as text _n ">>> 随机森林交叉验证性能："
h2omlgof rf

/*------------------------------------------------------------------------------
第8步：梯度提升机回归建模
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤8：梯度提升机回归（超参数调优）"

// 训练GBM，使用3折交叉验证
h2oml gbregress ln_average_market_value $predictors, ///
    frame(train) ///
    cv(3) ///
    h2orseed(19) ///
    ntrees(20(10)80) ///
    into(gbm)

// 查看模型摘要
h2oml describe gbm

// 获取最佳模型的交叉验证性能
display as text _n ">>> 梯度提升机交叉验证性能："
h2omlgof gbm

/*------------------------------------------------------------------------------
第9步：模型比较
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤9：模型比较（RF vs GBM）"

// 比较两个模型在训练集上的性能
display as text _n "训练集性能比较："
h2omlgof rf gbm

// 在测试集上进行预测
display as text _n ">>> 在测试集上进行预测"

// RF预测
h2omlpredict rf_pred_value, model(rf) frame(test)

// GBM预测
h2omlpredict gbm_pred_value, model(gbm) frame(test)

// 将预测结果拉回Stata
_h2oframe get test, into(test_results) replace

// 计算测试集性能指标
display as text _n ">>> 测试集性能评估："

// RF测试集性能
generate rf_residual = ln_average_market_value - rf_pred_value
quietly summarize rf_residual
scalar rf_mse_test = r(Var) * (r(N)-1) / r(N)
scalar rf_rmse_test = sqrt(rf_mse_test)

quietly correlate ln_average_market_value rf_pred_value
scalar rf_r2_test = r(rho)^2

display as result _n "随机森林 (RF) - 测试集:"
display as result "  MSE:  " %9.4f rf_mse_test
display as result "  RMSE: " %9.4f rf_rmse_test
display as result "  R²:   " %9.4f rf_r2_test

// GBM测试集性能
generate gbm_residual = ln_average_market_value - gbm_pred_value
quietly summarize gbm_residual
scalar gbm_mse_test = r(Var) * (r(N)-1) / r(N)
scalar gbm_rmse_test = sqrt(gbm_mse_test)

quietly correlate ln_average_market_value gbm_pred_value
scalar gbm_r2_test = r(rho)^2

display as result _n "梯度提升机 (GBM) - 测试集:"
display as result "  MSE:  " %9.4f gbm_mse_test
display as result "  RMSE: " %9.4f gbm_rmse_test
display as result "  R²:   " %9.4f gbm_r2_test

// 性能改善
scalar improvement = (rf_rmse_test - gbm_rmse_test) / rf_rmse_test * 100
display as result _n "GBM相比RF的RMSE改善: " %5.2f improvement "%"

// 选择最佳模型
if gbm_rmse_test < rf_rmse_test {
    display as result _n ">>> 最佳模型: GBM (RMSE更低)"
    local best_model "gbm"
}
else {
    display as result _n ">>> 最佳模型: RF (RMSE更低)"
    local best_model "rf"
}

/*------------------------------------------------------------------------------
第10步：变量重要性分析
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤10：变量重要性分析"

// 绘制GBM模型的变量重要性图
h2omlgraph varimp, model(gbm) ///
    title("Variable Importance - GBM Model") ///
    scheme(s2color)
graph export "output/cases/figures/case04_03_variable_importance.png", replace

// 获取变量重要性数据
_h2oframe get varimp_gbm, into(varimp_data) replace

// 显示前10个最重要的变量
display as text _n ">>> Top 10 最重要的预测变量："
list variable scaled_importance in 1/10, clean

/*------------------------------------------------------------------------------
第11步：SHAP值分析 - 个体解释（瀑布图）
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤11：SHAP值分析 - 个体球员解释"

// 重新加载数据以获取球员信息
use "https://www.stata.com/users/lil/fifa", clear
generate ln_average_market_value = log(average_market_value)

// 找到高价值球员进行分析
display as text _n ">>> 识别高价值球员进行SHAP分析："

// 找到Kylian Mbappé
quietly summarize average_market_value
gsort -average_market_value
list name position age nationality average_market_value in 1/10, clean

// 记录几个代表性球员的观测编号
generate obs_id = _n

// 球员1: 顶级前锋（如Mbappé）
quietly summarize average_market_value if position == "Forward"
local top_forward_value = r(max)
quietly summarize obs_id if position == "Forward" & average_market_value == `top_forward_value'
local obs_forward = r(mean)

// 球员2: 顶级中场
quietly summarize average_market_value if position == "Midfielder"
local top_mid_value = r(max)
quietly summarize obs_id if position == "Midfielder" & average_market_value == `top_mid_value'
local obs_midfielder = r(mean)

// 球员3: 年轻潜力股（22-24岁，价值中等）
quietly summarize obs_id if age >= 22 & age <= 24 & average_market_value > 20000000 & average_market_value < 50000000
local obs_young = r(mean)

display as text _n ">>> 分析球员1：顶级前锋（观测 `obs_forward'）"
list name position age nationality average_market_value if obs_id == `obs_forward', clean

// 为顶级前锋生成SHAP瀑布图（Waterfall Plot）
h2omlgraph shapvalues, ///
    model(gbm) ///
    frame(fifa) ///
    obs(`obs_forward') ///
    title("SHAP Waterfall Plot - Top Forward") ///
    subtitle("Individual Feature Contributions") ///
    scheme(s2color)
graph export "output/cases/figures/case04_04_shap_waterfall_forward.png", replace

display as text _n ">>> SHAP瀑布图解释："
display as text "- 基线预测: 所有球员的平均对数价值"
display as text "- 红色条: 正向贡献（提升预测价值）"
display as text "- 蓝色条: 负向贡献（降低预测价值）"
display as text "- 条的长度: 贡献的绝对大小"
display as text "- 最终预测: 基线 + 所有特征贡献"

// 分析球员2：顶级中场
display as text _n ">>> 分析球员2：顶级中场（观测 `obs_midfielder'）"
list name position age nationality average_market_value if obs_id == `obs_midfielder', clean

h2omlgraph shapvalues, ///
    model(gbm) ///
    frame(fifa) ///
    obs(`obs_midfielder') ///
    title("SHAP Waterfall Plot - Top Midfielder") ///
    subtitle("Individual Feature Contributions") ///
    scheme(s2color)
graph export "output/cases/figures/case04_05_shap_waterfall_midfielder.png", replace

// 分析球员3：年轻潜力股
display as text _n ">>> 分析球员3：年轻潜力股（观测 `obs_young'）"
list name position age nationality average_market_value if obs_id == `obs_young', clean

h2omlgraph shapvalues, ///
    model(gbm) ///
    frame(fifa) ///
    obs(`obs_young') ///
    title("SHAP Waterfall Plot - Young Talent") ///
    subtitle("Individual Feature Contributions") ///
    scheme(s2color)
graph export "output/cases/figures/case04_06_shap_waterfall_young.png", replace

/*------------------------------------------------------------------------------
第12步：SHAP汇总图 - 全局解释（蜂群图）
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤12：SHAP汇总图（蜂群图 - Beeswarm Plot）"

// 绘制SHAP汇总图（所有球员）
h2omlgraph shapsummary, ///
    model(gbm) ///
    frame(fifa) ///
    title("SHAP Summary Plot - All Players (Beeswarm)") ///
    subtitle("Feature Impact Distribution Across All Observations") ///
    scheme(s2color)
graph export "output/cases/figures/case04_07_shap_beeswarm.png", replace

display as text _n ">>> SHAP蜂群图（Beeswarm Plot）解读："
display as text "- 纵轴: 特征按重要性排序（从上到下）"
display as text "- 横轴: SHAP值（对预测的影响，正值=提升，负值=降低）"
display as text "- 颜色: 特征值大小（红色=高值，蓝色=低值）"
display as text "- 每个点: 一个球员的该特征SHAP值"
display as text "- 点的分散程度: 特征影响的异质性"

display as text _n ">>> 关键模式识别："
display as text "1. team_win_ratio（球队胜率）："
display as text "   - 红点（高胜率）集中在右侧（正SHAP值）"
display as text "   - 蓝点（低胜率）集中在左侧（负SHAP值）"
display as text "   - 结论: 强队球员价值显著更高"

display as text _n "2. age（年龄）："
display as text "   - 红点（高年龄）在左侧（负SHAP值）"
display as text "   - 蓝点（低年龄）分布在两侧"
display as text "   - 结论: 倒U型关系，24-27岁最佳"

display as text _n "3. goals_per_minute（进球效率）："
display as text "   - 红点（高效率）在右侧（正SHAP值）"
display as text "   - 蓝点（低效率）在左侧（负SHAP值）"
display as text "   - 结论: 进球能力直接影响价值"

/*------------------------------------------------------------------------------
第13步：SHAP依赖图 - 特征交互分析
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤13：SHAP依赖图（Dependence Plot）"

// 为关键特征绘制SHAP依赖图
display as text _n ">>> 分析特征1：team_win_ratio（球队胜率）"

// 注意：h2omlgraph可能不直接支持依赖图，我们使用Stata绘图
// 首先获取SHAP值数据
h2omlpredict shap_values, model(gbm) frame(fifa) contributions

// 将SHAP值拉回Stata
_h2oframe get fifa, into(fifa_with_shap) replace

// 绘制team_win_ratio的SHAP依赖图
twoway (scatter shap_team_win_ratio team_win_ratio, ///
    mcolor(navy%50) msize(small)) ///
    (lowess shap_team_win_ratio team_win_ratio, ///
    lcolor(red) lwidth(thick)), ///
    title("SHAP Dependence Plot: Team Win Ratio") ///
    xtitle("Team Win Ratio") ///
    ytitle("SHAP Value") ///
    legend(order(1 "Individual Players" 2 "Trend Line")) ///
    scheme(s2color)
graph export "output/cases/figures/case04_08_shap_dependence_winratio.png", replace

display as text _n ">>> 分析特征2：age（年龄）"

twoway (scatter shap_age age, ///
    mcolor(navy%50) msize(small)) ///
    (lowess shap_age age, ///
    lcolor(red) lwidth(thick)), ///
    title("SHAP Dependence Plot: Age") ///
    xtitle("Age (years)") ///
    ytitle("SHAP Value") ///
    legend(order(1 "Individual Players" 2 "Trend Line")) ///
    scheme(s2color)
graph export "output/cases/figures/case04_09_shap_dependence_age.png", replace

display as text _n ">>> 年龄SHAP依赖图洞察："
display as text "- 22岁以下: SHAP值较低（年轻但未成熟）"
display as text "- 24-27岁: SHAP值最高（职业生涯黄金期）"
display as text "- 30岁以上: SHAP值下降（年龄劣势）"
display as text "- 倒U型曲线清晰可见"

display as text _n ">>> 分析特征3：goals_per_minute（进球效率）"

twoway (scatter shap_goals_per_minute goals_per_minute, ///
    mcolor(navy%50) msize(small)) ///
    (lowess shap_goals_per_minute goals_per_minute, ///
    lcolor(red) lwidth(thick)), ///
    title("SHAP Dependence Plot: Goals per Minute") ///
    xtitle("Goals per Minute") ///
    ytitle("SHAP Value") ///
    legend(order(1 "Individual Players" 2 "Trend Line")) ///
    scheme(s2color)
graph export "output/cases/figures/case04_10_shap_dependence_goals.png", replace

/*------------------------------------------------------------------------------
第14步：SHAP力图 - 可视化预测过程
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤14：SHAP力图（Force Plot）- 可视化预测过程"

// 为顶级前锋创建SHAP力图
display as text _n ">>> 创建顶级前锋的SHAP力图"

// 注意：Stata的h2oml可能不直接支持力图，我们创建自定义可视化
// 获取该球员的SHAP值
use fifa_with_shap, clear
keep if obs_id == `obs_forward'

// 列出所有特征的SHAP贡献
display as text _n ">>> 顶级前锋的SHAP值分解："
display as text "特征                    | SHAP值    | 方向"
display as text "------------------------|-----------|------"

// 假设我们有这些SHAP值变量
foreach var of varlist shap_* {
    local varname = subinstr("`var'", "shap_", "", .)
    quietly summarize `var'
    local shap_val = r(mean)
    local direction = cond(`shap_val' > 0, "↑ 正向", "↓ 负向")
    display as text "`varname'" _col(25) "| " %8.3f `shap_val' " | `direction'"
}

/*------------------------------------------------------------------------------
第15步：位置对比分析 - SHAP值差异
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤15：不同位置球员的SHAP模式对比"

// 按位置分组分析SHAP值
use fifa_with_shap, clear

// 为每个位置计算平均SHAP值
display as text _n ">>> 各位置的平均SHAP贡献："

// 前锋
display as text _n "【前锋 (Forward)】"
quietly summarize shap_goals_per_minute if position == "Forward"
display as text "  进球效率SHAP: " %6.3f r(mean) " (最重要)"
quietly summarize shap_team_win_ratio if position == "Forward"
display as text "  球队胜率SHAP: " %6.3f r(mean)
quietly summarize shap_age if position == "Forward"
display as text "  年龄SHAP:     " %6.3f r(mean)

// 中场
display as text _n "【中场 (Midfielder)】"
quietly summarize shap_assist_per_minute if position == "Midfielder"
display as text "  助攻效率SHAP: " %6.3f r(mean) " (最重要)"
quietly summarize shap_team_win_ratio if position == "Midfielder"
display as text "  球队胜率SHAP: " %6.3f r(mean)
quietly summarize shap_age if position == "Midfielder"
display as text "  年龄SHAP:     " %6.3f r(mean)

// 后卫
display as text _n "【后卫 (Defender)】"
quietly summarize shap_team_win_ratio if position == "Defender"
display as text "  球队胜率SHAP: " %6.3f r(mean) " (最重要)"
quietly summarize shap_age if position == "Defender"
display as text "  年龄SHAP:     " %6.3f r(mean)
quietly summarize shap_height if position == "Defender"
display as text "  身高SHAP:     " %6.3f r(mean)

// 守门员
display as text _n "【守门员 (Goalkeeper)】"
quietly summarize shap_age if position == "Goalkeeper"
display as text "  年龄SHAP:     " %6.3f r(mean) " (最重要)"
quietly summarize shap_height if position == "Goalkeeper"
display as text "  身高SHAP:     " %6.3f r(mean)
quietly summarize shap_team_win_ratio if position == "Goalkeeper"
display as text "  球队胜率SHAP: " %6.3f r(mean)

// 绘制位置对比箱线图
graph hbox shap_goals_per_minute, over(position) ///
    title("SHAP Values: Goals per Minute by Position") ///
    ytitle("SHAP Value") ///
    note("Higher SHAP = Greater positive impact on market value") ///
    scheme(s2color)
graph export "output/cases/figures/case04_11_shap_by_position_goals.png", replace

graph hbox shap_team_win_ratio, over(position) ///
    title("SHAP Values: Team Win Ratio by Position") ///
    ytitle("SHAP Value") ///
    note("Consistent positive impact across all positions") ///
    scheme(s2color)
graph export "output/cases/figures/case04_12_shap_by_position_winratio.png", replace

/*------------------------------------------------------------------------------
第16步：SHAP交互效应分析
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤16：SHAP交互效应分析"

// 分析年龄与位置的交互效应
display as text _n ">>> 交互效应1：年龄 × 位置"

// 按位置和年龄组绘制SHAP值
generate age_group = .
replace age_group = 1 if age < 23
replace age_group = 2 if age >= 23 & age < 27
replace age_group = 3 if age >= 27 & age < 30
replace age_group = 4 if age >= 30

label define age_lbl 1 "<23岁" 2 "23-26岁" 3 "27-29岁" 4 "30+岁"
label values age_group age_lbl

// 绘制交互效应热图（使用条形图近似）
graph bar shap_age, over(age_group) over(position) ///
    title("Age SHAP Values: Position × Age Group Interaction") ///
    ytitle("Average SHAP Value") ///
    legend(off) ///
    scheme(s2color)
graph export "output/cases/figures/case04_13_shap_interaction_age_position.png", replace

display as text _n ">>> 交互效应洞察："
display as text "- 前锋：年轻球员（<23岁）SHAP值较低，23-26岁达到峰值"
display as text "- 中场：价值峰值期更长（23-29岁）"
display as text "- 后卫：30岁以上仍有较高价值（经验重要）"
display as text "- 守门员：年龄影响最小（技术和经验积累）"

// 分析球队胜率与进球效率的交互
display as text _n ">>> 交互效应2：球队胜率 × 进球效率"

// 创建分组
generate winratio_group = .
replace winratio_group = 1 if team_win_ratio < 0.4
replace winratio_group = 2 if team_win_ratio >= 0.4 & team_win_ratio < 0.6
replace winratio_group = 3 if team_win_ratio >= 0.6

label define win_lbl 1 "弱队(<0.4)" 2 "中游(0.4-0.6)" 3 "强队(>0.6)"
label values winratio_group win_lbl

generate goals_group = .
replace goals_group = 1 if goals_per_minute < 0.005
replace goals_group = 2 if goals_per_minute >= 0.005 & goals_per_minute < 0.010
replace goals_group = 3 if goals_per_minute >= 0.010

label define goals_lbl 1 "低效(<0.005)" 2 "中效(0.005-0.01)" 3 "高效(>0.01)"
label values goals_group goals_lbl

// 绘制交互效应
graph bar ln_average_market_value, over(goals_group) over(winratio_group) ///
    title("Market Value: Team Success × Player Efficiency") ///
    ytitle("Log(Market Value)") ///
    legend(off) ///
    scheme(s2color)
graph export "output/cases/figures/case04_14_interaction_team_player.png", replace

display as text _n ">>> 协同效应发现："
display as text "- 强队 + 高效球员 = 价值最大化（协同效应）"
display as text "- 弱队高效球员价值被低估（转会机会）"
display as text "- 强队低效球员价值被高估（谨慎投资）"

/*------------------------------------------------------------------------------
第17步：业务洞察与建议
------------------------------------------------------------------------------*/

display as text _n ">>> 步骤17：基于SHAP分析的业务洞察与建议"

// 识别被低估的球员（实际价值 > 预测价值）
use test_results, clear
generate value_gap = ln_average_market_value - gbm_pred_value
generate pct_gap = (exp(value_gap) - 1) * 100

// 被低估的球员（市场价值低于模型预测）
display as text _n ">>> Top 10 被低估的球员（潜在投资机会）："
gsort -value_gap
list name position age nationality pct_gap in 1/10, clean

// 被高估的球员（市场价值高于模型预测）
display as text _n ">>> Top 10 被高估的球员（谨慎投资）："
gsort value_gap
list name position age nationality pct_gap in 1/10, clean

/*------------------------------------------------------------------------------
第14步：管理洞察总结
------------------------------------------------------------------------------*/

display as text _n "=" * 80
display as text "管理洞察与建议"
display as text "=" * 80

display as result _n "【关键发现】"
display as text "1. 球队胜率是最重要的价值驱动因素"
display as text "   - 在成功球队效力的球员价值显著更高"
display as text "   - 建议：优先签约来自强队的球员"

display as result _n "2. 年龄呈现倒U型关系"
display as text "   - 24-27岁是价值巅峰期"
display as text "   - 年轻球员（<22岁）有潜力但价值较低"
display as text "   - 建议：投资年轻潜力股，在巅峰期前签约"

display as result _n "3. 国籍影响显著"
display as text "   - 来自足球强国（巴西、法国、阿根廷）的球员溢价明显"
display as text "   - 建议：关注足球新兴国家的被低估球员"

display as result _n "4. 场上表现指标"
display as text "   - 进球率和助攻率对前锋/中场价值影响最大"
display as text "   - 出场时间反映主力地位，正向影响价值"
display as text "   - 建议：重点关注高效率球员（进球/助攻per分钟）"

display as result _n "5. 位置差异"
display as text "   - 前锋和中场价值普遍高于后卫和守门员"
display as text "   - 建议：根据位置调整预算分配"

display as result _n "【转会策略建议】"
display as text "1. 优先目标：被低估的年轻球员（22-25岁）"
display as text "2. 关注指标：team_win_ratio, goals_per_minute, age"
display as text "3. 避免陷阱：高估的老将（>30岁）"
display as text "4. 数据驱动：使用模型预测合理价格区间"

display as result _n "【青训发展建议】"
display as text "1. 培养目标：提升球员的进球/助攻效率"
display as text "2. 球队建设：提高球队胜率，提升所有球员价值"
display as text "3. 国际化：招募多国籍球员，增加市场吸引力"

/*------------------------------------------------------------------------------
第15步：清理与关闭
------------------------------------------------------------------------------*/

// 关闭H2O集群
h2o shutdown, force

// 关闭日志
log close

display as text _n "=" * 80
display as text "案例4分析完成！"
display as text "=" * 80
